Resize an existing array
ReDim $array[subscript 1]...[subscript n]
Parameters
$variable | The name of the variable to resize. |
subscript | The number of elements to create for the array dimension, indexed 0 to n-1. |
Remarks
The ReDim keyword is similar to Dim, except that ReDim preserves the values in the array instead of removing the values while resizing an array. The number of dimensions must remain the same, or the old array will be forgotten during the ReDim. The array will retain the scope (Global or Local) that it had prior to resizing.
Related
Dim, UBound
Example
; Example Resizing an array
Dim $I, $K, $T, $MSG
Dim $X[4][6], $Y[4][6]
For $I = 0 To 3
For $K = 0 To 5
$T = Int(Random(20) + 1) ;Get random numbers between 1 and 20
$X[$I][$K] = $T
$Y[$I][$K] = $T
Next
Next
ReDim $X[3][8]
Dim $Y[3][8]
$MSG = ""
For $I = 0 To UBound($X, 1) - 1
For $K = 0 To UBound($X, 2) - 1
If $K > 0 Then $MSG = $MSG & ", "
$MSG = $MSG & $X[$I][$K]
Next
$MSG = $MSG & @CR
Next
MsgBox(0, "ReDim Demo", $MSG)
$MSG = ""
For $I = 0 To UBound($Y, 1) - 1
For $K = 0 To UBound($Y, 2) - 1
If $K > 0 Then $MSG = $MSG & ", "
$MSG = $MSG & $Y[$I][$K]
Next
$MSG = $MSG & @CR
Next
MsgBox(0, "ReDim Demo", $MSG)